package cn.melonlib.nars.names.model.entity;

import cn.melonlib.cores.jpa.model.bean.collections.JsonMap;
import cn.melonlib.cores.model.anno.ModelComment;
import cn.melonlib.nars.names.model.enmus.FileType;
import cn.melonlib.nars.names.model.enmus.NamesType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

@ModelComment("本地存储文件")
@Data
@EqualsAndHashCode(callSuper = true)
@Entity(name = "MelonFile")
@Table(name = "nars_file")
public class MelonFile extends MelonNames{

    public MelonFile(){
        setNamesType(NamesType.FILE);
    }

    @ModelComment("文件大小")
    private Long fileSize;

    @ModelComment("文件解析方式")
    private String contentType;

    @ModelComment("扩展名称")
    private String extendName;

    @ModelComment("文件类型")
    private FileType fileType=FileType.OTHER;

    @ModelComment("服务器物理存放路径")
    @Column
    @Lob
    @Basic(fetch = FetchType.LAZY)@Type(type = "org.hibernate.type.TextType")
    private String storePath;

    public File file(){
        return new File(storePath);
    }

    @Override
    public String exts() throws Exception{
        return JsonMap.createMap().append("extName",extendName).append("size",fileSize).append("contentType",contentType)
                .jsonString();
    }
}
